import Layout from '@/layout'

export function tranformRoutes(routes) {
  const res = []
  routes.forEach(route => {
    const tmp_route = { ...route }
    const tmp = {
      path: tmp_route.path,
      component: Layout,
      alwaysShow: tmp_route.alwaysShow,
      // name: tmp_route.name,
      meta: {
        title: tmp_route.title,
        icon: tmp_route.icon,
        roles: tmp_route.roles
      },
      children: []
    }

    route.children.forEach(child => {
      const tmp_child = { ...child }
      tmp.children.push({
        path: tmp_child.path,
        component: () => import(`@/views${tmp_route.path}/${tmp_child.path}`),
        name: tmp_route.name + ':' + tmp_child.path,
        meta: {
          title: tmp_child.title,
          roles: tmp_child.roles
        }
      })
    })
    res.push(tmp)
  })

  return res
}

export function inArray(value, items) {
  return items.some(function (item) {
    return value == item
  })
}

export function removeValInArray(value, items) {
  var index = items.indexOf(value);
  if (index > -1) {
    items.splice(index, 1);
  }
}